﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Aweber;

namespace Aweber.Example
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Replace with the keys of your application
            // NEVER SHARE OR DISTRIBUTE YOUR APPLICATIONS'S KEYS!
            // It is recommended you place these within your web.config application settings
            String consumerKey = ConfigurationManager.AppSettings["AweberConsumerKey"]; // "vjckuVc3sNrZWOa3PWnf";
            String consumerSecret = ConfigurationManager.AppSettings["AweberConsumerSecret"]; // "u3sQ7vGGJZPCKhgEOAXeqgBSi685c5x2wm6gZuIj";

            // Create a new api instance
            API api = new API(consumerKey, consumerSecret);

            // Set callback url (if not set will default to this page)
            api.CallbackUrl = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Authorize.aspx";

            // Get request token
            api.get_request_token();

            // Save the token and secret in session 
            HttpContext.Current.Session.Add("oauth_token", api.OAuthToken);
            HttpContext.Current.Session.Add("oauth_token_secret", api.OAuthTokenSecret);

            // Will redirect user to the Aweber authorize page
            api.authorize();


        }
    }
}

